package clientGUI.user.ISD;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;

import java.awt.Label;

import javax.swing.JComboBox;

import javax.swing.JButton;


import clientGUI.user.Controllers.ISD.ChooseSupervisorController;
import clientGUI.userPanels.UPanel;
import clientserver.Client;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;


public class ISDChooseSupervisor extends UPanel {

	int rid;
	private JLabel lblcurrent;
	private ChooseSupervisorController controller;
	private JComboBox<String> choosingCB;
	private ISDChoose  tabfather;
	private JComboBox<String> ridCB;


	public ISDChooseSupervisor(int id,Client cl) {
		
		super();

	
	
		controller=new ChooseSupervisorController(id, cl);
		controller.readonlyaddedRequests();

		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		
		
		ArrayList<String> all= controller.getCandidates();
		
		lblcurrent = new JLabel(controller.buildcurrentsupervisorlabel());
		GridBagConstraints gbc_currenlbl = new GridBagConstraints();
		gbc_currenlbl.insets = new Insets(0, 0, 5, 5);
		gbc_currenlbl.gridx = 2;
		gbc_currenlbl.gridy = 0;
		add(lblcurrent, gbc_currenlbl);
								rid = (int) id;

	setName("Supervisor");
	ArrayList<String> box = new ArrayList<String>();
	box = controller.getallrids();
				
				JLabel lblChoo = new JLabel("Choose Supervisor  for Request :");
				GridBagConstraints gbc_lblChoo = new GridBagConstraints();
				gbc_lblChoo.anchor = GridBagConstraints.EAST;
				gbc_lblChoo.insets = new Insets(0, 0, 5, 5);
				gbc_lblChoo.gridx = 1;
				gbc_lblChoo.gridy = 2;
				add(lblChoo, gbc_lblChoo);
			
				
				
				ridCB = new JComboBox(box.toArray());
				GridBagConstraints gbc_ridCB = new GridBagConstraints();
				gbc_ridCB.insets = new Insets(0, 0, 5, 5);
				gbc_ridCB.fill = GridBagConstraints.HORIZONTAL;
				gbc_ridCB.gridx = 2;
				gbc_ridCB.gridy = 2;
				add(ridCB, gbc_ridCB);
			
			Label label = new Label("Engeneer:");
			GridBagConstraints gbc_label = new GridBagConstraints();
			gbc_label.insets = new Insets(0, 0, 5, 5);
			gbc_label.gridx = 1;
			gbc_label.gridy = 3;
			add(label, gbc_label);
	
			choosingCB = new JComboBox(all.toArray());
			
					GridBagConstraints gbc_choosingCB = new GridBagConstraints();
					gbc_choosingCB.fill = GridBagConstraints.HORIZONTAL;
					gbc_choosingCB.insets = new Insets(0, 0, 5, 5);
					gbc_choosingCB.gridx = 2;
					gbc_choosingCB.gridy = 3;
					
					
					
					
					
					add(choosingCB, gbc_choosingCB);
	
	JButton btnSet = new JButton("Set Supervisor");
	btnSet.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			
			
			String supervisor=(String)choosingCB.getSelectedItem();
			controller.SetSupervisor(supervisor);
			lblcurrent.setText(controller.buildcurrentsupervisorlabel());
			
		}
	});
	GridBagConstraints gbc_btnSet = new GridBagConstraints();
	gbc_btnSet.insets = new Insets(0, 0, 5, 5);
	gbc_btnSet.gridx = 2;
	gbc_btnSet.gridy = 4;
	add(btnSet, gbc_btnSet);
	}

}
